/**
 * 用户修改密码
 * @type {{regAction: string}}
 */
var urlParams   = {editPassAction:webRoot+"/login/editUserPass"};

$(function(){
    var userInfo = session.userInfo;
    console.info(userInfo);
	initEvent();
});

/**
 * 添加监听
 */
function initEvent(){
    $(".lang-btn").click(function () {
        var userInfo = session.userInfo;
        if(!userInfo){
            alert("用户没登录，请先登录！");
            window.location.href = webRoot+"login/user";
        }
        var passport = $("#passport").val();
        var passport1 = $("#passport1").val();
        var passport2 = $("#passport2").val();
        var checkPass = MatchesClass.checkPass(passport);
        var checkNewPass = MatchesClass.checkPass(passport1);
        if(checkPass!="success"){
            return alert(checkPass);
        }else if(passport1.length != passport2.length){
            return alert("两次新密码输入不一致!");
        }else if(checkNewPass!="success"){
            return alert(checkNewPass);
        }
        var pass = $.md5(passport);
        var newPass = $.md5(passport1);
        $.ajax({
            type: 'post',
            url: urlParams.editPassAction,
            cache: false,
            data: {id:userInfo.id,password:pass,newPass:newPass},
            dataType: 'json',
            success: function (data) {
                if(data){
                    alert(data.msg);
                    if(data.success){
                        window.location.href = webRoot+"login/user";
                    }
                }
            },
            error:function(){
            }
        });
    });
}